<template>
  <div class="app-container calendar-list-container">
    <div class="filter-container">
      <el-input @keyup.enter.native="handleFilter"  style="width: 110px;" class="filter-item" placeholder="小程序编号" v-model="listQuery.storeAppId">
      </el-input>
       <el-input @keyup.enter.native="handleFilter" style="width: 110px;" class="filter-item" placeholder="店铺编号" v-model="listQuery.storeId">
      </el-input>
      <el-select clearable style="width: 110px" class="filter-item" v-model="listQuery.DevStatus" placeholder="状态">
        <el-option v-for="item in importanceOptions" :key="item.key" :label="item.display_name" :value="item.key">
        </el-option>
      </el-select>
      <el-select clearable style="width: 110px" class="filter-item" v-model="listQuery.NeedUpdate" placeholder="更新">
        <el-option v-for="item in needUpdateOptions" :key="item.key" :label="item.display_name" :value="item.key">
        </el-option>
      </el-select>
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="给我一点时间"  fit highlight-current-row
      style="width: 100%">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="创建日期">
            <span>{{ props.row.CreateTime }}</span>
          </el-form-item>
          
          <el-form-item label="上传时间">
            <span>{{ props.row.UploadTime == '1900-01-01 00:00:00'?'-':props.row.UploadTime }}</span>
          </el-form-item>
     
          <el-form-item label="提审时间">
            <span>{{ props.row.CommitTime == '1900-01-01 00:00:00'?'-':props.row.CommitTime }}</span>
          </el-form-item>
    
          <el-form-item label="发布时间">
            <span>{{ props.row.ReleaseTime == '1900-01-01 00:00:00'?'-':props.row.ReleaseTime }}</span>
          </el-form-item>
          <el-form-item label="腾讯审核">
            <span>编号:{{ props.row.AuditId }}-信息:{{ props.row.AuditInfo }}</span>
          </el-form-item>
      
        </el-form>
      </template>
    </el-table-column>

      <el-table-column align="center" label="小程序编号" width="100">
        <template slot-scope="scope">
          <span>{{scope.row.StoreAppId}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="店铺编号" width="85">
        <template slot-scope="scope">
          <span>{{scope.row.StoreId}}</span>
        </template>
      </el-table-column>
      <el-table-column width="80px" label="Logo">
        <template slot-scope="scope">
          <img :src="scope.row.Logo" class="logo-avatar" alt="">  
        </template>
      </el-table-column>
      <el-table-column min-width="150px" label="名称">
        <template slot-scope="scope">
          <span >{{scope.row.Name}}</span>
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="状态" width="100">
        <template slot-scope="scope">
          <el-tag :type="scope.row.DevStatus | statusFilter">{{scope.row.DevStatus | statusDisplayFilter}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="150px" align="center" label="使用模板">
        <template slot-scope="scope">
          <span>模板编号:{{scope.row.AppId}}</span>
          <span>模板版本:v{{scope.row.TemplateId}}</span>
        </template>
      </el-table-column>
      
      
      
      <el-table-column align="center" label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" v-bind:disabled="scope.row.NeedUpdate==0"  size="mini" @click="handleUpdate(scope.row.StoreAppId)">更新</el-button>
          <el-button type="text" v-bind:disabled="scope.row.DevStatus!=4"  size="mini" @click="handlePublish(scope.row.StoreAppId)">发布</el-button>
          <el-button type="text" size="mini"  @click="open5">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.itemsPerPage" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>


  </div>
</template>

<script>
import { fetchList, UpgradeStoreApp,ReleaseStoreApp } from "@/api/weapp";
import waves from "@/directive/waves"; // 水波纹指令
import { parseTime } from "@/utils";


export default {
  name: "complexTable",
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: [],
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        itemsPerPage: 30,
        storeId: '',
        storeAppId:'',
        appId:0,
        NeedUpdate:"-1",
        DevStatus:"-1"
      },
      importanceOptions:[
        { key: '-1', display_name: '审核状态' },
        { key: '0', display_name: '未知' },
        { key: '1', display_name: '待上传' },
        { key: '2', display_name: '已上传' },
        { key: '4', display_name: '待审核' },
        { key: '5', display_name: '已审核' },
        { key: '6', display_name: '已发布' }
      ],
      needUpdateOptions:[
        { key: '-1', display_name: '更新状态' },
        { key: '0', display_name: '不需要' },
        { key: '1', display_name: '需要' },
        
      ],
   

      showReviewer: false,
      
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        update: "Edit",
        create: "Create"
      },
      dialogPvVisible: false,
      pvData: [],
      downloadLoading: false
    };
  },
  filters: {
     statusFilter(status) {
      const statusMap = {
        "0": "danger",
        "1": "info",
        "2": "info",
        "3": "info",
        "4": "success",
        "5": "success"
      };
      return statusMap[status];
    },
    statusDisplayFilter(status) {
      const statusMap = {
        "0": "未知",
        "1": "待上传",
        "2": "已上传",
        "3": "待审核",
        "4": "已审核",
        "5": "已发布"
      };
      return statusMap[status];
    }
  },
  created() {
    const h = this.$createElement;
        this.$notify({
          title: '小程序审核葵花宝典',
          dangerouslyUseHTMLString: true,
          message: '<a style=\'color:teal\' href=\'http://47.96.160.198/youpengfei/QiDong.OMS.Web/blob/master/README-WEIXIN.md\' target=\'_blank\'>点击查看最新的小程序审核规则</a>'
        });
    this.getList();
  },
  methods: {
    getList() {
      //列表数据
      this.listLoading = true;
      fetchList(this.listQuery).then(response => {
        if (response.data.Code === 0) {
          this.list = response.data.Data.Items;
          this.total = response.data.Data.TotalItems;
        } else {
          this.$message({
            type: "danger",
            message: response.data.Message
          });
        }
        this.listLoading = false;
      });
    },
    
    //详情页弹出框
    open5() {
        this.$alert('<strong>详情页</strong>', '', {
          dangerouslyUseHTMLString: true
        });
      },

    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    //更新小程序模板
    handleUpdate(row) {
      this.$confirm("是否确认更新?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          UpgradeStoreApp({ StoreAppId: row }).then(response => {
            if (response.data.Code == 0) {
              this.$message({
                type: "success",
                message: "更新成功!"
              });
               this.getList();
            } else {
              this.$message({
                type: "info",
                message: response.data.Message
              });
            }
          })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消更新"
          });
        });
    })},
    //更新小程序模板
    handlePublish(row) {
      this.$confirm("是否确认发布?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          ReleaseStoreApp({ StoreAppId: row }).then(response => {
            if (response.data.Code == 0) {
              this.$message({
                type: "success",
                message: "发布成功!"
              });
            } else {
              this.$message({
                type: "info",
                message: response.data.Message
              });
            }
          })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消发布"
          });
        });
    })}
  }
};
</script>
<style scoped>
.logo-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

